#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
const int maxn = 1e6;
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	int n;
	sd(n);
	string s1;
	cin >> s1;

	if (s1.size() == 1)
	{
		cout << "YES";
		puts("");
		return;
	}

	unordered_map<char, int> cnt;

	for (int i = 0; i < n;)
	{
		int flag = 0;
		if (cnt[s1[i]]!=0)
		{
			cout << "NO" << '\n';
			return;
		}
		while (i < n - 1 && s1[i] == s1[i + 1])
		{
			cnt[s1[i]]++;
			i++;
			flag = 1;
		}
		if (flag == 1 && i < n)
		{
			if (s1[i] == s1[i - 1])
				cnt[s1[i]]++;
			i++;
			continue;

		}
		if (flag != 1)
		{
			if (cnt[s1[i]] != 0)
			{
				cout << "NO" << '\n';
				return;
			}
			cnt[s1[i]]++;
			i++;
		}
	}
	cout << "YES" << '\n';
	return;

}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}